#include <windows.h>
#include "resource.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
HDC hdc;
#define V 5
LPCTSTR ClsName = "WIN32 API BASICS";
LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
typedef struct generatii{
	char nume[10];
	char prenume[10];
	char d_nasterii[11];
	int stg,sus,dpt,jos;
	generatii *next;
}gen;
typedef struct vlist{
	int generatie;
	gen * head;
	vlist * next;
	vlist * prev;
}vlist;
struct LI
{	int stg, sus, dpt, jos;
	int x,y;
	vlist*head;
};
LI S[5];
vlist * head=NULL;
//int genmax=0;
void clc_screen(HWND hwnd)
{
    PAINTSTRUCT Ps;
	HPEN	   hPen;
	HBRUSH brush=CreateSolidBrush(RGB(79,147,249));
	hPen = CreatePen(PS_NULL, 1,RGB(79,147,249) );
    SelectObject(hdc, brush);
	SelectObject(hdc,hPen);
	int a,b,c,d;
	vlist * elem=head;
	gen * el;
	while(elem!=NULL)
	{
		el=elem->head;
		while(el!=NULL)
		{
			a=el->sus-2;
			b=el->jos+2;
			c=el->stg-2;
			d=el->dpt+2;
			Rectangle(hdc,c,a,d,b);
			el=el->next;
		}
		elem=elem->next;
	}
	DeleteObject(brush);
	DeleteObject(hPen);
}
void clear()
{
	vlist * elem=head,*aux2;
	gen * el,*aux;
	while(elem!=NULL)
	{
		el=elem->head;
		while(el!=NULL)
		{
				aux=el;
				el=el->next;
				free(aux);
		}
		aux2=elem;
		elem=elem->next;
		free(aux2);
		head=NULL;
	}
}
void actualizare()
{
	int x,y;
	vlist * elem=head;
	gen * el;
	while(elem!=NULL)
	{
		el=elem->head;
		while(el!=NULL)
		{
				x=el->dpt+5;
				y=el->sus;
				SetBkColor(hdc,RGB(79,147,249));
				SetTextColor(hdc,RGB(79,147,249));
				TextOut(hdc,x,y,"TRUE",4);
				TextOut(hdc,x,y,"FALSE",5);
				el=el->next;
		}
		elem=elem->next;
	}

		
}
void afisare(HWND hwnd)
{
	HBRUSH brush=CreateSolidBrush(RGB(79,147,249));
    SelectObject(hdc,brush);
	int a,b,c,d,x,y;
	char P[30];
	gen * el;
	vlist * elem=head;
	int g;
	if(head==NULL)
	{
		MessageBox(hwnd,"Lista este vida !","Eroare",MB_OK | MB_ICONERROR);
	}
	else
	{
		while(elem!=NULL)
		{
			el=elem->head;
			g=elem->generatie;
			a=S[g].dpt+30;
			b=S[g].stg-30;
			c=S[g].sus+50;
			d=S[g].jos+70;
			x=S[g].stg-20;
			y=S[g].y+55;
			while(el!=NULL)
			{
				el->dpt=a;
				el->jos=d;
				el->stg=b;
				el->sus=c;
				strcpy(P,el->nume);
				strcat(P,"  ");
				strcat(P,el->prenume);
				Rectangle(hdc, b, c, a, d);
				SetBkColor(hdc,RGB(79,147,249));
				SetTextColor(hdc,RGB(239,244,15));
				TextOut(hdc, x+20, y-2, P, strlen(P));
				TextOut(hdc, x+35, y+15, el->d_nasterii, strlen(el->d_nasterii));
				el=el->next;
				c=c+50;
				d=d+50;
				y=y+50;
			}
			elem=elem->next;
		} 
	}
	  DeleteObject(brush);
}
void inserare_membru(char num[],char prenum[],char d_nast[])
{
	if(head!=NULL)
	{
	vlist*elem;
	if (head->generatie==1)
	{
		elem=new vlist;
		elem->prev=NULL;
		elem->generatie=0;
		elem->next=head;
		head->prev=elem;
		elem->head=NULL;
	}
	else 
	{
			elem=head;
	}
	head=elem;
	gen*el;
	if (elem->head==NULL)
	{
		el=new gen;
		assert(el!=NULL);
		strcpy(el->nume,num);
		strcpy(el->prenume,prenum);
		strcpy(el->d_nasterii,d_nast);
		el->next=NULL;
		elem->head=el;
	}
	else
	{
		gen *last=elem->head;
		el=new gen;
		while(last->next!=NULL)
		{
			last=last->next;
		}
		strcpy(el->nume,num);
		strcpy(el->prenume,prenum);
		strcpy(el->d_nasterii,d_nast);
		el->next=NULL;
		last->next=el;
	}
	}
	else
	{
	return;
	}
}
int inserare_date (HWND hwnd);
int cautare_date (HWND hwnd);
BOOL CALLBACK dialog1 (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
		int ok;
        switch (msg)
        {
        case WM_INITDIALOG:
                return TRUE;
                break;
        case WM_COMMAND:
                switch (LOWORD(wParam))
                {
				case IDC_BUTTON1:
					actualizare();
					ok=inserare_date(hwnd);
					if (ok)
					{
						EndDialog(hwnd, 0);
						MessageBox(hwnd,"Datele au fost introduse cu succes in lista !", "Inserare reusita", MB_ICONINFORMATION);
					}
					else 
					{
						MessageBox(hwnd,"Datele nu au fost introduse cu succes in lista !", "Inserare nereusita", MB_ICONWARNING);
						
					}
				break;
				}
		break;
		case WM_CLOSE:
			EndDialog(hwnd,0);
		break;
		 
		default:
			return FALSE;
		}
		return TRUE;
}
BOOL CALLBACK dialog2 (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	int ok;
	switch(msg)
	{
	case WM_INITDIALOG:
		return TRUE;
		break;
	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case IDC_BUTTON3:
			actualizare();
			afisare(hwnd);
			ok=cautare_date(hwnd);
			if (ok)
			{
				EndDialog(hwnd, 0);
				if(MessageBox(hwnd,"Cautarea a avut loc cu succes ! Doriti sa aflati detalii ?", "Cautare reusita", MB_YESNO | MB_ICONINFORMATION)==IDYES)
					MessageBox(hwnd,"A inceput cautarea ! Are loc cautarea membrului introdus de la tastatura. Scopul listelor V este de a parcurge, in acest caz, toata lista de generatii, de la jumatatea inferioara pana la cea superioara. Sansele de a gasi un membru in jumatatea inferioara sunt de 50%, ca mai apoi sansele sa se injumatateasca pe masura ce este parcursa lista. Demonstratorul va returna FALSE in dreptul unui membru ce nu corespunde parametrilor cautarii si TRUE, daca s-a gasit membrul dorit.","Detalii",MB_OK | MB_ICONINFORMATION);
			}
			else 
			{
				MessageBox(hwnd,"Cautarea nu a avut loc in lista !", "Cautare nereusita", MB_ICONWARNING);		
			}
		break;
			}
	break;
	case WM_CLOSE:
		EndDialog(hwnd,0);
	break;
	default:
		return FALSE;
	}
	return TRUE;
}
BOOL CALLBACK dialog3 (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	int ok;
	switch(msg)
	{
	case WM_INITDIALOG:
		return TRUE;
		break;
	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
			case IDOK:
			{
				EndDialog(hwnd,0);
				MessageBox(hwnd,"Va Multumim !","Succes",MB_OK | MB_ICONINFORMATION);
			}
			break;
		}
		break;
	case WM_CLOSE:
		EndDialog(hwnd,0);
	break;
	default:
		return FALSE;
	}
	return TRUE;
}
void inserare( int g, char nume[],char prenume[],char data[])
{
	vlist * elem=new vlist;
	gen * el=new gen;
	strcpy(el->nume,nume);
	strcpy(el->prenume,prenume);
	strcpy(el->d_nasterii,data);
	el->next=NULL;
	elem->generatie=g;
	elem->head=el;
	elem->next=NULL;
	elem->prev=NULL;
	if(head==NULL)
	{
		//genmax++;
		head=elem;
	}
	else
	{
		vlist * search=head,*aux;
		int ok=1;
		while((search!=NULL)&&(ok==1)&&(search->generatie<=g))
		{
			if(search->generatie==g)
			{
				ok=0;
			}
			aux=search;
			search=search->next;
		}
		if(ok==0)
		{
			if(aux->head==NULL)
			{
				aux->head=el;
			}
			else
			{
				gen * last=aux->head;
				while(last->next!=NULL)
				{
					last=last->next;
				}
				last->next=el;
			}
		}
		else
		{
			if(search==NULL)
			{
				//genmax++;
				search=aux;
				search->next=elem;
				elem->prev=search;
			}
		}
	}
}
int inserare_fisier (char *filename)
{
        FILE *f;
        f=fopen(filename,"r");
		assert(f);
        if (f==NULL)
        {
                MessageBox(NULL,"Eroare la deschiderea fisierului","ERROR", MB_OK|MB_ICONERROR);
                return 0;
        }
		char s[50], nume[10],prenume[10],data[30],*p,*c;
		c=NULL;
		strcpy(s,"");
		strcpy(nume,"");
		strcpy(prenume,"");
		strcpy(data,"");
		int i;
		c=fgets(s,50,f);
		if (c==NULL)
		{
			MessageBox(NULL,"Fisierul este gol !", "Eroare", MB_OK | MB_ICONWARNING);
			assert(f);
			fclose(f);
			return 0;
		}
		while(c)
		{
			s[strlen(s)-1]='\0';
			p=strtok(s," ");
			i=atoi(p);
			if (!i)
			{
				MessageBox(NULL,"Baza de date foloseste date incorecte !","Eroare",MB_OK);
				return 0;
			}
			p=strtok(NULL," ");
			strcpy(nume,p);
			p=strtok(NULL," ");
			strcpy(prenume,p);
			p=strtok(NULL," ");
			strcpy(data,p);
			inserare(i,nume,prenume,data);
			c=fgets(s,100,f);
		}
		fclose(f);
		return 1;
}
void init_list()
{
	HBRUSH brush=CreateSolidBrush(RGB(79,147,249));
	 SelectObject(hdc,brush);
	int k;
	for (k=0;k<V;k++)
	S[k].head=NULL;
	S[0].sus=80;
	S[0].dpt=220;
	S[0].stg=120;
	S[0].jos=100;
	S[0].x=130;
	S[0].y=82;
	for (k=1;k<V;k++)
	{
		S[k].stg=S[k-1].stg+230;
		S[k].sus=S[k-1].sus;
		S[k].dpt=S[k-1].dpt+230;
		S[k].jos=S[k-1].jos;
		S[k].x=S[k-1].x+230;
		S[k].y=S[k-1].y; 
	}
	
	SetBkColor(hdc,RGB(79,147,249));
	for (k=0;k<V;k++)
	{
		Rectangle(hdc,S[k].stg,S[k].sus,S[k].dpt,S[k].jos);
	}
	SetTextColor(hdc,RGB(9,9,0));
	TextOut(hdc,S[0].x,S[0].y,"Generatia 0",11);
	TextOut(hdc,S[1].x,S[1].y,"Generatia 1",11);
	TextOut(hdc,S[2].x,S[2].y,"Generatia 2",11);
	TextOut(hdc,S[3].x,S[3].y,"Generatia 3",11);
	TextOut(hdc,S[4].x,S[4].y,"Generatia 4",11);
	DeleteObject(brush);
}
int inserare_date (HWND hwnd)
{
	int cuv1,cuv2,cuv3Z,cuv3L,cuv3A,a,b;
	char *buf1,*buf2,*buf3Z,*buf3L,*buf3A;
	cuv1=GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT3));
	if (cuv1==0)
	{
		MessageBox(hwnd,"Campul nume nu a fost introdus. Reintroduceti numele dorit !","Eroare-Nume",MB_OK | MB_ICONWARNING);
		return 0; 
	}
	else
		if (cuv1>0)
		{
			buf1=(char*)malloc(sizeof(char)*(cuv1+1));
			GetDlgItemText(hwnd,IDC_EDIT3,buf1,cuv1+1);
			for (int h=0;h<cuv1;h++)
			{
				if (isdigit(buf1[h]))
				{
					MessageBox(hwnd,"Introduceti doar litere in campul Nume !","Eroare !",MB_OK | MB_ICONERROR);
					return 0;
				}
			}
		}
	cuv2=GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT4));
	if (cuv2==0)
	{
		MessageBox(hwnd,"Campul prenume nu a fost introdus. Reintroduceti prenumele dorit !","Eroare-Prenume", MB_OK | MB_ICONWARNING);
		return 0;
	}
	else
		if (cuv2>0)
		{
			buf2=(char*)malloc(sizeof(char)*(cuv2+1));
			GetDlgItemText(hwnd,IDC_EDIT4,buf2,cuv2+1);
			for (int h=0;h<cuv2;h++)
			{
				if (isdigit(buf2[h]))
				{
					MessageBox(hwnd,"Introduceti doar litere in campul Prenume !","Eroare !",MB_OK | MB_ICONERROR);
					return 0;
				}
			}
		}
	cuv3Z=GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT5));
	if (cuv3Z==0)
	{
		MessageBox(hwnd,"Campul data nasterii nu a fost introdus. Reintroduceti ziua nasterii dorita !","Eroare-Data Nasterii", MB_OK | MB_ICONWARNING);
		return 0;
	}
	else
	{
			buf3Z=(char*)malloc(sizeof(char)*(cuv3Z+1));
			GetDlgItemText(hwnd,IDC_EDIT5,buf3Z,cuv3Z+1);
			a=atoi(buf3Z);
		if ((a>0)&&(a<32))
		{
			for (int h=0;h<cuv3Z;h++)
			{
				if (isalpha(buf3Z[h]))
				{
					MessageBox(hwnd,"Ziua nasterii e intre 1 si 31 ale lunii !","Eroare !",MB_OK | MB_ICONERROR);
					return 0;
				}
			}
		}
		else
				{
					MessageBox(hwnd,"Campul ziua nasterii nu contine toata informatia necesara. Reintroduceti informatia dorita !","Eroare", MB_OK | MB_ICONERROR);
					return 0;
				}
	}
	cuv3L=GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT6));
	if (cuv3L==0)
	{
		MessageBox(hwnd,"Campul luna nasterii nu a fost introdus. Reintroduceti luna nasterii dorita !","Eroare-Data Nasterii", MB_OK | MB_ICONWARNING);
		return 0;
	}
	else
	{
			buf3L=(char*)malloc(sizeof(char)*(cuv3L+1));
			GetDlgItemText(hwnd,IDC_EDIT6,buf3L,cuv3L+1);
			b=atoi(buf3L);
		if ((b>0)&&(b<13))
		{
			for (int h=0;h<cuv3L;h++)
			{
				if (isalpha(buf3L[h]))
				{
					MessageBox(hwnd,"Luna nasterii e intre 1 si 12 ale anului !","Eroare !",MB_OK | MB_ICONERROR);
					return 0;
				}
			}
		}		
		else
				{
					MessageBox(hwnd,"Campul luna nasterii nu contine toata informatia necesara. Reintroduceti informatia dorita !","Eroare", MB_OK | MB_ICONERROR);
					return 0;
				}
	}
	cuv3A=GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT7));
	if (cuv3A==0)
	{
		MessageBox(hwnd,"Campul anul nasterii nu a fost introdus. Reintroduceti anul nasterii dorit !","Eroare-Data Nasterii", MB_OK | MB_ICONWARNING);
		return 0;
	}
	else
		if ((cuv3A==4))
		{
			buf3A=(char*)malloc(sizeof(char)*(cuv3A+1));
			GetDlgItemText(hwnd,IDC_EDIT7,buf3A,cuv3A+1);
			for (int h=0;h<cuv3A;h++)
			{
				if (isalpha(buf3A[h]) && atoi(buf3A) < 1000) 
				{
					MessageBox(hwnd,"Anul nasterii e intre 1000 si 9999 !","Eroare !", MB_OK | MB_ICONERROR);
					return 0;
				}
			}
		}		
		else
				{
					MessageBox(hwnd,"Campul anul nasterii nu contine toata informatia necesara. Reintroduceti informatia dorita !","Eroare", MB_OK | MB_ICONERROR);
					return 0;
				}
		if ((cuv1>0) && (cuv2>0) && ((a>0) && (a<32)) && ((b>0) && (b<13)) && (cuv3A==4) && (atoi(buf3A)>1000))
		{
			char data [20];
			strcpy(data,buf3Z);
			strcat(data,"-");
			strcat(data,buf3L);
			strcat(data,"-");
			strcat(data,buf3A);
			inserare_membru(buf1,buf2,data);
			assert((buf1!=NULL)&&(buf2!=NULL)&&(buf3Z!=NULL)&&(buf3L!=NULL)&&(buf3A!=NULL));
			free(buf1);free(buf2);free(buf3Z);free(buf3L);free(buf3A);
			return 1;
		}
		else return 0;
}
int cautare_date (HWND hwnd)
{
	int cuv4, cuv5;
	char *buf4,*buf5;
	cuv4=GetWindowTextLength(GetDlgItem(hwnd, IDC_EDIT1));
	if (cuv4==0)
	{
		MessageBox(hwnd,"Campul nume nu a fost introdus. Reintroduceti numele dorit !", "Eroare-Nume", MB_OK | MB_ICONWARNING);
		return 0;
	}
	else
		if (cuv4>0)
		{
			buf4=(char*)malloc(sizeof(char)*(cuv4+1));
			GetDlgItemText(hwnd,IDC_EDIT1,buf4,cuv4+1);
			for (int h=0;h<cuv4;h++)
			{
				if (isdigit(buf4[h]))
				{
					MessageBox(hwnd,"Introduceti doar litere in campul Nume !","Eroare",MB_OK | MB_ICONERROR);
					return 0;
				}
			}
		}
	cuv5=GetWindowTextLength(GetDlgItem(hwnd,IDC_EDIT2));
	if (cuv5==0)
	{
		MessageBox(hwnd,"Campul prenume nu a fost introdus. Reintroduceti prenumele dorit !", "Eroare-Prenume", MB_OK | MB_ICONWARNING);
		return 0;
	}
	else
	{
		if (cuv5>0)
		{
			buf5=(char*)malloc(sizeof(char)*(cuv5+1));
			GetDlgItemText(hwnd,IDC_EDIT2,buf5,cuv5+1);
			for (int h=0;h<cuv5;h++)
			{
				if (isdigit(buf5[h]))
				{
					MessageBox(hwnd,"Introduceti doar litere in campul Prenume !","Eroare", MB_OK | MB_ICONERROR);
					return 0;
				}
			}
		}
	}
	int x,y;
	vlist * elem=head;
	if(elem!=NULL)
	{
	while(elem->next!=NULL)
	{
		elem=elem->next;
	}
	while(elem!=NULL)
	{
		gen *el=elem->head;
		while(el!=NULL)
		{
			x=el->dpt+5;
			y=el->sus;
			if((stricmp(buf4,el->nume)==0)&&(stricmp(buf5,el->prenume)==0))
			{
				SetBkColor(hdc,RGB(79,147,249));
				SetTextColor(hdc,RGB(25,255,2));
				TextOut(hdc,x,y,"TRUE",4);
				return 1;
			}
			else
			{
				SetBkColor(hdc,RGB(79,147,249));
				SetTextColor(hdc,RGB(255,25,2));
				TextOut(hdc,x,y,"FALSE",5);
			}
			el=el->next;
		}
		elem=elem->prev;
	}
	}
	assert(buf4!=NULL);
	assert(buf5!=NULL);
	free(buf4);
	free(buf5);
	return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
		int i;
        HWND d1=NULL, d2=NULL, d3=NULL;
		HDC hDC; OPENFILENAME fon;  
		char szFileName[MAX_PATH] = "";
		HPEN bluePen; HGDIOBJ oldPen;
		PAINTSTRUCT pntstruct;
		HFONT font;
        switch(msg)
        {
		case WM_CREATE:
			break;
		case WM_PAINT:
			hDC=BeginPaint(hwnd,&pntstruct);
			font=CreateFont(35,20,0,0,FW_NORMAL,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
			CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_ROMAN,"Elephant");
			SelectObject(hDC,font);
			SetBkColor(hDC,RGB(79,147,249));
			TextOut(hDC,350,35,"Demonstrator Grafic - Liste V",29);
			DeleteObject(font);
			EndPaint(hwnd,&pntstruct);
		break;	
        case WM_COMMAND:
                switch(LOWORD (wParam))
                {
				case ID_DESCHIDERE_FISIER:
					 if (MessageBox (hwnd,"Doriti adaugarea datelor ?","Adaugare", MB_YESNO | MB_ICONINFORMATION)==IDNO)
                        {
                               MessageBox(hwnd,"Lista nu a fost initializata", "Eroare", MB_OK | MB_ICONINFORMATION);
                        }
					   else
                        {
                                hdc=GetDC(hwnd);
                                ZeroMemory(&fon, sizeof(fon));
                                fon.lStructSize = sizeof(fon);
                                fon.hwndOwner = hwnd;
                                fon.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
                                fon.lpstrFile = szFileName;
                                fon.nMaxFile = MAX_PATH;
                                fon.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
                                fon.lpstrDefExt = "txt";
                                if(GetOpenFileName(&fon))
                                {
										if (head==NULL)
										{
										init_list();
                                        i=inserare_fisier(szFileName); 
										if (i==1)
										{
										MessageBox(NULL," Lista Creata cu Succes","Fisier Nou", MB_OK | MB_ICONINFORMATION);
										}
										}
										else
										{
											MessageBox(hwnd,"Lista este deja populata. Nu se mai poate introduce alta baza de date.","Eroare",MB_OK);
										}
                                }
								
						}
                break;
                case WM_SHOWWINDOW:
                        break;
                case ID_FILE_OPEN40002:
						MessageBox(hwnd,"VA MULTUMIM !	","Exit", MB_OK | MB_ICONINFORMATION);
						clear();
                        PostQuitMessage(0);
                        break;
				case ID_AFISARE_DATE:
					{
						if (MessageBox(hwnd,"Doriti vizualizarea listelor de generatii ?","Vizualizare", MB_YESNO | MB_ICONINFORMATION)==IDYES)
						{
							init_list();
							actualizare();
							afisare(hwnd);
						}
					}
				break;
				case ID_INSERARE_DATE:
					d1=CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_DIALOG1),hwnd,dialog1);
                        if (d1!=NULL)
                        {
                                ShowWindow(d1,SW_SHOW);
                        }
                        else
                        {
                                MessageBox(hwnd,"Eroare la crearea dialogului 1","EROARE",MB_OK | MB_ICONERROR);
                        }
				break;
				case ID_CAUTARE_DATE:
					d2=CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_DIALOG2),hwnd,dialog2);
						if (d2!=NULL)
                        {
                                ShowWindow(d2,SW_SHOW);
                        }
                        else
                        {
                                MessageBox(hwnd,"Eroare la crearea dialogului 2","EROARE",MB_OK | MB_ICONERROR);
                        }
				break;
				case ID_OPERATII_STERGEREDATE:
					actualizare();
					clc_screen(hwnd);
					clear();
					MessageBox(NULL,"Stergerea s-a efectuat cu succes !","Succes", MB_OK);
					break;
				case ID_AJUTOR_DESPREAPLICATIE:
					d3=CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_DIALOG3),hwnd,dialog3);
					if (d3!=NULL)
					{
						ShowWindow(d3,SW_SHOW);
					}
					else
					{
						MessageBox(hwnd,"Eroare la deschiderea dialogului 3","EROARE",MB_OK | MB_ICONERROR);
					}
					break;
				case ID_AJUTOR_SUPORTTEHNIC:
					MessageBox(hwnd,"Suportul tehnic este asigurat de catre specialistii Academiei Tehnice Militare","Suport Tehnic",MB_OK);
					break;

				}
				break;
				case WM_CLOSE:
					clear();
					PostQuitMessage(0);
				break;
        default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{              
        WNDCLASSEX wc;
        HWND hwnd;
        MSG Msg;
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.style = CS_HREDRAW|CS_VREDRAW;
        wc.lpfnWndProc = WndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = LoadIcon(NULL, IDI_INFORMATION);
        wc.hCursor = LoadCursor(NULL, IDC_HAND);
        wc.hbrBackground = CreateSolidBrush(RGB(79,147,249));
        wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
        wc.lpszClassName = ClsName;
        wc.hIconSm = LoadIcon(NULL, IDI_INFORMATION);
        if(!RegisterClassEx(&wc))
        {
                MessageBox(NULL, "Eroare la crearea ferestrei Windows!", "Eroare!", MB_ICONEXCLAMATION | MB_OK);
                return 0;
        }
        hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, ClsName, "LISTA GENERATIILOR - APLICABILITATEA LISTELOR V   ------   Versiunea 1.0", WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 1366, 768, NULL, NULL, hInstance, NULL);
        if(hwnd == NULL)
        {
                MessageBox(NULL, "Eroare la crearea ferestrei Windows!", "Eroare!", MB_ICONEXCLAMATION | MB_OK);
                return 0;
        }
        DialogBox(NULL, MAKEINTRESOURCE(IDD_DLGFIRST),
                  hwnd, reinterpret_cast<DLGPROC>(DlgProc));


        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
        while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
                TranslateMessage(&Msg);
                DispatchMessage(&Msg);
        }
        return Msg.wParam;
}
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
        switch(Msg)
        {
        case WM_INITDIALOG:
                return TRUE;


        case WM_COMMAND:
                switch(wParam)
                {
                case WM_DESTROY:
                        PostQuitMessage(0);
                        break;
                case IDOK:
                        EndDialog(hWndDlg, 0);
                        return TRUE;
                }
                break;
        }


        return FALSE;
}
